package co.edu.eafit.rfp.web.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import co.edu.eafit.rfp.backend.entity.charge.Charge;
import co.edu.eafit.rfp.backend.services.charge.ChargeServices;
import co.edu.eafit.rfp.backend.services.mail.SendMailServices;
import co.edu.eafit.rfp.backend.services.user.UserServices;

import com.google.gson.Gson;



@SuppressWarnings("restriction")
@Controller
public class holaAjaxController extends BaseController{

	@Autowired
	//	private DepartmentServices departmentServices;
	private ChargeServices chargeServices;
	//	private Department department;
	//	private Charge charge;
	private UserServices userServices;
	
	
	@Autowired
	private SendMailServices correo;
	
	public void init(){

	}

	@RequestMapping(value = "/holaAjax", method = RequestMethod.GET)
	public ModelAndView holaAjax()throws Exception{
		return new ModelAndView("holaAjax.jsp");
	}

	@RequestMapping(value="/searchCharge", method=RequestMethod.GET)
	public @ResponseBody String getcharge(@RequestParam String mail, @RequestParam String name) {
		System.out.println(mail + " - "+ name +" Capturado desde el controlador");
		List<Charge> chargeList = new ArrayList<Charge>();
		Charge c1 = new Charge("Carggo1", "Mi cargo es feliz", null);
		Charge c2 = new Charge("Carggo2", "M cargo es feliz2", null);
		chargeList.add(c1);
		chargeList.add(c2);
		Gson g = new Gson();
		String result = g.toJson(chargeList);
		return result;
		//		List<Charge>  charges= chargeServices.getAllChargeByDepartmentId(departmentId);
		//	    return charges;
	}

	@RequestMapping(value="/sendMail", method=RequestMethod.GET)
	public @ResponseBody String sendMail(@RequestParam String mail, @RequestParam String name) {
		System.out.println(mail + " - "+ name +" Capturado desde el controlador");
		correo.sendMail();
		List<Charge> chargeList = new ArrayList<Charge>();
		Charge c1 = new Charge("Carggo1", "Mi cargo es feliz", null);
		Charge c2 = new Charge("Carggo2", "Mi cargo es feliz2", null);
		chargeList.add(c1);
		chargeList.add(c2);
		Gson g = new Gson();
		String result = g.toJson(chargeList);
		return result;
		//		List<Charge>  charges= chargeServices.getAllChargeByDepartmentId(departmentId);
		//	    return charges;
	}


}
